package hu;

import java.util.*;

public class hu39 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while(sc.hasNextLine()) {
            String[] maskCode = sc.nextLine().split("\\.");
            String[] code1 = sc.nextLine().split("\\.");
            String[] code2 = sc.nextLine().split("\\.");
            isSameNet(maskCode, code1, code2);
        }
    }
    public static void isSameNet(String[] maskCode, String[] code1, String[] code2){
        for (int i = 0; i < 4; i++) {
            int a = Integer.parseInt(maskCode[i]);
            int b = Integer.parseInt(code1[i]);
            int c = Integer.parseInt(code2[i]);
            if(!isMaskCode(maskCode)){
                System.out.println(1);
                return;
            }
            if(a > 255 || b > 255 || c > 255 || a < 0 || b < 0 || c < 0){
                System.out.println(1);
                return;
            }
        }
        for (int i = 0; i < 4; i++) {
            int a = Integer.parseInt(maskCode[i]);
            int b = Integer.parseInt(code1[i]);
            int c = Integer.parseInt(code2[i]);
            if((a & b) != (a & c)){
                System.out.println(2);
                return;
            }
        }
        System.out.println(0);
    }
    public static boolean isMaskCode(String[] maskCode) {
        String s = "";
        for (int i = 0; i < maskCode.length; i++) {
            if(Integer.toBinaryString(Integer.parseInt(maskCode[i])).length() < 8){
                for (int j = 0; j < 8 - Integer.toBinaryString(Integer.parseInt(maskCode[i])).length(); j++) {
                    s += "0";
                }
            }
            s += Integer.toBinaryString(Integer.parseInt(maskCode[i]));
        }
        int t = 0;
        for (int i = 0; i < s.length(); i++) {
            if (s.charAt(i) == '0') {
                t = i;
                break;
            }
        }
        for (int i = t; i < s.length(); i++) {
            if (s.charAt(i) == '1') {
                return false;
            }
        }
        return true;
    }
}